from django.db import models


class admin(models.Model): #admin table
    admin_name =\
        models.CharField(max_length=32,primary_key=True)
    admin_pwd=models.CharField(max_length=32)


class ShopTable(models.Model): # table of shop entity
    Shop_id = models.CharField(max_length=100, primary_key=True) # shop id as primary key. It is from crawler
    Shop_name = models.CharField(max_length=100) # shop name
    Shop_address = models.CharField(max_length=100) #shop address

class MerchTable(models.Model): # table of Merchandise entity
    Merch_id = models.CharField(max_length=100, primary_key=True) # Merchandise id, from crawler
    Merch_name = models.CharField(max_length=100) # Merchandise name
    Merch_img = models.ImageField()# Network address of Merchandise img
    Merch_tag = models.CharField(max_length=100)# merchandise tag
    Merch_price = models.CharField(max_length=100) #price
    Merch_sid = models.ForeignKey(ShopTable, on_delete=models.CASCADE) #id of the shop that merchandise belongs to. It is a foreign key



class UserTable(models.Model): # table of User entity. The data is created by actually user
    User_id = models.CharField(max_length=100, primary_key=True) # user id. It is created by our platform
    User_psw = models.CharField(max_length=100) # password
    User_name = models.CharField(max_length=100) # name
    User_phone = models.CharField(max_length=100) # phone number
    User_address = models.CharField(max_length=100) # user address

class CartTable(models.Model): # table of Cart entity. The data is created by user's action. Django will create an id automatically as primary key
    Cert_mid = models.ForeignKey(MerchTable, on_delete=models.CASCADE) # Merchandise id. It is a foreign key
    Cert_sid = models.ForeignKey(ShopTable, on_delete=models.CASCADE) # shop id. It is a foreign key
    Cert_uid = models.ForeignKey(UserTable, on_delete=models.CASCADE) # user id. It is a foreign key
    Cert_amount = models.IntegerField(default=0) # amount of each Merchandise

class OrderTable(models.Model):# table of Order entity. The data is created by user's action
    Order_id = models.CharField(max_length=100, primary_key=True) # order id.It is a primary key
    Order_date = models.DateTimeField(auto_now=True, auto_now_add=False) # order date. It recorded the time that the order is created
    Order_amount = models.IntegerField(default=0) # order amount
    Order_mid = models.ForeignKey(MerchTable, on_delete=models.CASCADE) # Merchandise id. It is a foreign key
    Order_sid = models.ForeignKey(ShopTable, on_delete=models.CASCADE) # shop id. It is a foreign key
    Order_uid = models.ForeignKey(UserTable, on_delete=models.CASCADE) # user id. It is a foreign key




# class LogTable(models.Model):  # 物流单
#     Log_id = models.CharField(max_length=100, primary_key=True)
#     Log_from = models.CharField(max_length=100)  # Shop_address
#     Log_to = models.CharField(max_length=100)  # User_address
#     log_Uphone = models.ImageField()  # User_phone
#     Log_oid = models.ForeignKey(OrderTable, on_delete=models.CASCADE)
#     Log_cid = models.ForeignKey(CourierTable, on_delete=models.CASCADE)

# class CourierTable(models.Model):
#     Courier_id = models.CharField(max_length=100, primary_key=True)
#     Courier_name = models.CharField(max_length=100)
#     Courier_phone = models.IntegerField(default=100)